package plus.stmt;

import plus.run.Label;
import plus.util.Cons;

abstract class Loop extends Statement {
	
	static Cons<Loop> chain = null;
	final Label again = new Label(), after = new Label();
	final String label;
	Loop(String label) { this.label = label; }
	public boolean answersTo(String name) {
		if (null == name) return true;
		if (label == name) return true;
		return false;
	}
	protected void enter() { chain = new Cons<Loop>(this, chain); }
	protected void exit()  { chain = chain.tail; }
	
	public static Loop find(String name) {
		Cons<Loop> link = chain;
		while (link != null) {
			if (link.head.answersTo(name)) return link.head;
			else link = link.tail;
		}
		return null;
	}
	
}
